package online.shenjian.kafka;

import org.apache.kafka.common.serialization.Deserializer;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serializer;

import java.util.Map;

public class CustomerAnalysisSerde implements Serde<CustomerAnalysis> {
    private final Serializer<CustomerAnalysis> serializer;
    private final Deserializer<CustomerAnalysis> deserializer;

    public CustomerAnalysisSerde() {
        this.serializer = new JsonSerializer<>();
        this.deserializer = new JsonDeserializer<>(CustomerAnalysis.class);
    }

    @Override
    public void configure(Map<String, ?> configs, boolean isKey) {
        serializer.configure(configs, isKey);
        deserializer.configure(configs, isKey);
    }

    @Override
    public Serializer<CustomerAnalysis> serializer() {
        return serializer;
    }

    @Override
    public Deserializer<CustomerAnalysis> deserializer() {
        return deserializer;
    }

    @Override
    public void close() {
        serializer.close();
        deserializer.close();
    }
}
